package com.fhzn.auth.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户类型枚举
 *
 * @author fhzn
 */
@Getter
public enum UserTypeEnum {

    /**
     * 未知
     */
    UNKNOWN(-1, null, null),

    /**
     * 内部员工
     */
    INNER(1, "内部员工", "INNER_OP"),

    /**
     * 外包员工
     */
    OUTSOURCE(2, "外部员工", "OUTSOURCE_OP"),

    ;

    private final Integer code;
    private final String desc;
    private final String adminCode;


    UserTypeEnum(Integer code, String desc, String adminCode) {
        this.code = code;
        this.desc = desc;
        this.adminCode = adminCode;
    }


    public static UserTypeEnum fromCode(Integer code) {
        if (code == null) {
            return UNKNOWN;
        }
        for (UserTypeEnum userType : values()) {
            if (userType.getCode().intValue() == code.intValue()) {
                return userType;
            }
        }
        return UNKNOWN;
    }


    public static UserTypeEnum fromDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return UserTypeEnum.UNKNOWN;
        }
        for (UserTypeEnum typeEnum : UserTypeEnum.values()) {
            if (desc.equals(typeEnum.getDesc())) {
                return typeEnum;
            }
        }
        return UserTypeEnum.UNKNOWN;
    }

    public static boolean isInnerUser(Integer code) {
        UserTypeEnum userType = fromCode(code);
        return userType == UserTypeEnum.INNER;
    }

    public static boolean isOuterUser(Integer code) {
        UserTypeEnum userType = fromCode(code);
        return userType == UserTypeEnum.OUTSOURCE;
    }
}
